<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script>
			
			function f1 (a,b) {
				return a+b;
			}
			
			function f1 (a,b,c) {
				return a*b*c;
			}
			
			console.log(f1(2,3));//
			console.log(f1(2,3,4));//24
			
			
					/*function add () {
				var sum = 0; 
				for (var i = 0; i <arguments.length; i++){
					sum+=arguments[i];
				}
				return sum;
			}*/
			
			//定义一个函数：当传入2个参数时 实现相加，当传入3个参数时 实现相乘
				function add () {
				var sum = 0; 
				var div = 1; 
				if (arguments.length==2) {
					for (var i = 0; i <arguments.length; i++){
					sum+=arguments[i];
				}
				    return sum;
				} else{
					for (var i = 0; i <arguments.length; i++){
					div*=arguments[i];
				}
					return div;
				}
				}
				
				document.write(add(4,5)+"<br />");
			    document.write(add(4,5,6));
			    console.log(add(4,5));
			    console.log(add(4,5,6));
		</script>
	</body>
</html>
